package com.cyclinggle.cloud;

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

import com.cyclinggle.cloud.model.User;
import com.cyclinggle.cloud.service.UserService;

@RestController
public class UserController implements UserService {
	
	private Map<String, User> mapping = new HashMap<>();
	
	@Override
	public String get(User user) {
		User res = mapping.get(buildKey(user));
		if (res != null) {
			return res.getName();
		}
		return "empty !";
	}

	@Override
	public String add(User user) {
		mapping.put(buildKey(user), user);
		return user.getName();
	}

	private String buildKey(User user) {
		return user.getDeptId() + "-" + user.getId();
	}

}
